import {get, post} from "../../utils/req";
import {alert} from "../../components/common/alert";

export async function list() {
    try {
        return await get('/private/referrer/list') || [];
    } catch (e) {
        alert(`获取推广人信息失败：${e}`, 'error');
        return [];
    }
}

export async function save(data) {
    try {
        await post('/private/referrer/save', data);
        return true;
    } catch (e) {
        alert(`保存推广人信息失败：${e}`, 'error');
        return false;
    }
}

export async function del(id) {
    try {
        await get(`/private/referrer/delete?id=${id}`);
        return true;
    } catch (e) {
        alert(`删除推广人信息失败：${e}`, 'error');
        return false;
    }
}

export async function commissions(data) {
    try {
        return await post('/private/referrer/commissions', data) || [];
    } catch (e) {
        alert(`获取佣金信息失败：${e}`, 'error');
        return [];
    }
}

export async function pay(id, date) {
    try {
        await get(`/private/referrer/pay?id=${id}&date=${date}`);
        return true;
    } catch (e) {
        alert(`修改佣金支付状态失败：${e}`, 'error');
        return false;
    }
}

export async function stat() {
    try {
        return await get('/private/referrer/stat') || null;
    } catch (e) {
        alert(`获取佣金统计信息失败：${e}`, 'error');
        return null;
    }
}
